package pl.edu.agh.lab2.sr.beans;

import java.io.Serializable;

public class Field implements Serializable {

	private static final long serialVersionUID = 6652389954607152353L;

	private static final int minY = 1;
	private static final int maxY = GameMap.getDimension();
	private static final char minX = 'A';
	private static final char maxX = (char) (minX + GameMap.getDimension() - 1);

	private char x;
	private int y;

	public Field(char x, int y) {
		if (!validateInput(x, y)) {
			throw new IllegalArgumentException("Bad shot coordinates: " + x + y
					+ ".");
		}
		this.x = x;
		this.y = y;
	}

	private boolean validateInput(char x2, int y2) {
		// X:
		if (x2 > maxX)
			return false;

		if (x2 < minX)
			return false;

		// Y:
		if (y2 > maxY)
			return false;

		if (y2 < minY)
			return false;

		return true;
	}

	public char getX() {
		return x;
	}

	public int getY() {
		return y;
	}

	public static int getMinY() {
		return minY;
	}

	public static int getMaxY() {
		return maxY;
	}

	public static char getMinX() {
		return minX;
	}

	public static char getMaxX() {
		return maxX;
	}

	public int getNormalizedX() {
		return this.x - getMinX();
	}

	public int getNormalizedY() {
		return this.y - getMinY();
	}

	public String toLongString() {
		return "Field [x=" + x + "(" + getNormalizedX() + "), y=" + y + " ("
				+ getNormalizedY() + ")]";
	}

	@Override
	public String toString() {
		return "" + x + y;
	}

	public static void main(String[] args) {
		System.out.println(getMinX());
		System.out.println(getMaxX());
		System.out.println(getMinY());
		System.out.println(getMaxY());
		System.out.println(getMaxX() - getMinX() + 1);
		System.out.println(getMaxY() - getMinY() + 1);

		Field f1 = new Field('A', 1);
		System.out.println(f1);
		f1 = new Field('J', 10);
		System.out.println(f1);

		f1 = new Field('A', 10);
		System.out.println(f1);

		f1 = new Field('J', 1);
		System.out.println(f1);

		f1 = new Field('D', 12);

	}

}
